from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Edge()
driver.get('http://10.59.9.14:7003/')
# 点击登录
driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
time.sleep(2)
# 输入账号密码
driver.find_element(By.CLASS_NAME,'regi-input').send_keys('15232008902')
driver.find_element(By.NAME,'password').send_keys('123456')
time.sleep(15)
# 相对点击登录
driver.find_element(By.XPATH,'/html/body/div[4]/div/div[1]/div[2]/form/div[5]/a').click()
time.sleep(2)
# 绝对l点击首页
driver.find_element(By.XPATH,'/html/body/div[3]/div[2]/ul/li[1]/a').click()
time.sleep(2)
# 向下滚动
driver.execute_script('window.scrollTo(0,400)')
time.sleep(2)
# 选择商品
driver.find_element(By.XPATH,'/html/body/div[8]/div[1]/div[2]/div[2]/ul/li[1]/div[1]/a/img').click()
time.sleep(2)
# 加入购物车
driver.find_element(By.XPATH,'//a[@id="add-cart" and @class="shop-btn"]').click()
time.sleep(2)
# 查看购物车
driver.find_element(By.CSS_SELECTOR,'.nav-settcart').click()
time.sleep(2)
# 打印句柄
# current_handle = driver.current_window_handle
# print("当前窗口句柄:", current_handle)
all_handles = driver.window_handles
print("所有窗口句柄:", all_handles)
a=driver.find_element(By.XPATH,'/html/body/div[4]/form/div[2]/div/a[2]')
print(a.text)
#①　文本值
print(a.text)
#②　获取元素的具体属性值（比如class）
print(a.get_attribute('class'))
#③　获取元素的宽高
print(a.size)
#④　获取元素的坐标值
print(a.location)
#⑤　打印元素是否可用
print(a.is_enabled())
#⑥　打印元素是否显示
print(a.is_selected())
# ⑦　打印元素是否被选中
print(a.is_displayed())
time.sleep(10)
driver.quit()
driver.implicitly_wait(10)
